Traducción al español será siempre la mayor brevedad
The inputFile component renders an file input HTML element. Users specify a file to upload either by entering the path to a file directly, or by clicking the Browse button to open a file-system navigation dialog window. Clicking the Upload button uploads the specified file to the server.
The inputFile component can be used to provide a user-specified file upload capability.
The inputFile component has two listeners progressListener and actionListener. The progressListener can notify the application on the percentage of the file being uploaded while the actionListener notifies the application about the state of the file. The progressListener is optional and only required when the Developer would like to inform the user of the File upload progress.
progressListener: These are some things to consider when implementing the progressListener.
public class MyBean {
private PersistentFacesState state = null;
private int percent = -1;
public MyBean() {
state = PersistentFacesState.getInstance();
}
/**
* This is the progressListener implementation
*/
public void progress (EventObject event) {
InputFile file = (InputFile)event.getSource();
percent = file.getFileInfo().getPercent();
try {
if (state != null) {
state.render();
}
} catch (RenderingException e) {
e.printStackTrace();
}
}
}
actionListener: These are some things to consider when implementing the actionListener.
public void action(ActionEvent event){
InputFile inputFile =(InputFile) event.getSource();
//file has been saved
if (inputFile.getStatus() == InputFile.SAVED) {
fileName = inputFile.getFileInfo().getFileName();
contentType = inputFile.getFileInfo().getContentType();
}
//invalid file, happens when clicking on upload without
selecting a file, or a file with no contents.
if (inputFile.getStatus() == InputFile.INVALID) {
inputFile.getFileInfo().getException().printStackTrace();
}
//file size exceeded the limit
if (inputFile.getStatus() == InputFile.SIZE_LIMIT_EXCEEDED) {
inputFile.getFileInfo().getException().printStackTrace();
}
//indicate that the request size is not specified.
if (inputFile.getStatus() == InputFile.UNKNOWN_SIZE) {
inputFile.getFileInfo().getException().printStackTrace();
}
}
The following code shows how to create a simple inputFile component:
<ice:inputFile />
|
tag-name:
|
<ice:inputFile>
|
|
tag-class:
|
com.icesoft.faces.component.inputfile.InputFileTag
|
|
component-class:
|
com.icesoft.faces.component.inputfile.InputFile
|
|
component-type:
|
com.icesoft.faces.File
|
|
component-family:
|
com.icesoft.faces.File
|
|
renderer-class:
|
com.icesoft.faces.component.inputfile.InputFileRenderer
|
|
renderer-type:
|
com.icesoft.faces.Upload
|